package ipc.project;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class User {
	
	private String login="";
	private String password="";
	private String status="";

	private ConnectionWithServer connection=new ConnectionWithServer();;
	private List<String> statuses = new ArrayList<String>();

	public User() {
		login = "";
		password = "";
		status="";
	}

	public User(SharedPreferences settings) {
		this.login = settings.getString("LOGIN", "");
		this.password = settings.getString("PASSWORD", "");
	}

	public User(String login, String password) {
		this.login = login;
		this.password = password;
	}

	public String getLogin() {
		return login;
	}

	public boolean checkConnection() {
		return connection.check();
	}

	public boolean signIn() {
		return checkInputInformation() && connection.signIn(login, password);
	}

	public boolean signUp() {
		return checkInputInformation() && connection.signUp(login, password);
	}

	public void signOut() {
		login = "";
		password = "";
		connection.signOut();
	}

	public boolean checkInputInformation() {
		return (login.length() * password.length() != 0);
	}

	public void saveData(SharedPreferences settings) {
		Editor ed = settings.edit();
		ed.putString("LOGIN", login);
		ed.putString("PASSWORD", password);
		ed.commit();
	}

	public String getCountOfOnlineFriends() {
		return Integer.toString(ConnectionWithServer.getCountOfOnlineFriends());
	}

	public void setStatus(String status) {
		connection.setStatus(status);
		this.status = status;
	}

	public void setStatus(long ind) {
		setStatus(statuses.get((int) ind));
	}

	public String getStatus() {
		return status;
	}
	public void addStatus(String status) {
		statuses.add(status);
	}

	public List<String> getStatuses() {
		return statuses;
	}
	
	public List<String> getRequests(boolean incoming) {
		return incoming ? connection.getInRequests() : connection.getOutRequests();
	}

	public List<Friend> getFriends(boolean online) {
		return online ? connection.getFriends() : connection.getOnlineFriends();
	}

	public void deleteFriend(String login) {
		connection.deleteFriend(login);
	}

	public void sendRequestToBeFriends(String login) {
		connection.sendRequest(login);
	}

	public void acceptRequest(String login) {
		connection.acceptRequest(login);
	}

	public void declineRequest(String login) {
		connection.declineRequest(login);
	}
}
